<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @copyright   Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php /** @var $this \Magento\Sales\Block\Adminhtml\Order\View\Tab\Info */ ?>
<?php $_order = $this->getOrder() ?>

<div id="order-messages">
    <?php echo $this->getChildHtml('order_messages') ?>
</div>

<?php echo $this->getChildHtml('order_info') ?>
<input type="hidden" name="order_id" value="<?php echo $_order->getId() ?>"/>

<?php if (!$_order->getIsVirtual()): ?>
<div class="clearfix">
<?php endif; ?>

    <div class="order-payment-method<?php if ($_order->getIsVirtual()): ?> order-payment-method-virtual<?php endif; ?>">
        <?php /* Payment Method */ ?>
        <div class="fieldset-wrapper">
            <div class="fieldset-wrapper-title">
                <span class="title"><?php echo __('Payment Information') ?></span>
            </div>
            <div><?php echo $this->getPaymentHtml() ?></div>
            <div class="order-payment-currency"><?php echo __('The order was placed using %1.', $_order->getOrderCurrencyCode()) ?></div>
            <div class="order-payment-additional"><?php echo $this->getChildHtml('order_payment_additional'); ?></div>
        </div>
    </div>

<?php if ($_order->getIsVirtual()): ?>
</div><?php /* opening div is in app\code\Magento\Sales\view\adminhtml\order\view\info.phtml */ ?>
<?php endif; ?>

<?php echo $this->getChildHtml('order_shipping_view') ?>

<?php if (!$_order->getIsVirtual()): ?>
</div>
<?php endif; ?>

<?php echo $this->getGiftOptionsHtml() ?>

<div class="fieldset-wrapper">
    <div class="fieldset-wrapper-title">
        <span class="title"><?php echo __('Items Ordered') ?></span>
    </div>
    <?php echo $this->getItemsHtml() ?>
</div>

<div class="clearfix">
    <div class="order-comments-history">
        <div class="fieldset-wrapper">
            <div class="fieldset-wrapper-title">
                <span class="title"><?php echo __('Comments History') ?></span>
            </div>
            <fieldset><?php echo $this->getChildHtml('order_history') ?></fieldset>
        </div>
    </div>

    <div class="order-totals">
        <div class="fieldset-wrapper">
            <div class="fieldset-wrapper-title">
                <span class="title"><?php echo __('Order Totals') ?></span>
            </div>
            <?php echo $this->getChildHtml('order_totals') ?>
        </div>
    </div>
</div>

<?php echo $this->getChildHtml('popup_window');?>

<script type="text/javascript">
require([
    "prototype",
    "Magento_Sales/order/giftoptions_tooltip"
], function(){

//<![CDATA[
    /**
     * Retrieve gift options tooltip content
     */
    function getGiftOptionsTooltipContent(itemId) {
        var contentLines = [];
        var headerLine = null;
        var contentLine = null;

        $$('#gift_options_data_' + itemId + ' .gift-options-tooltip-content').each(function (element) {
            if (element.down(0)) {
                headerLine = element.down(0).innerHTML;
                contentLine = element.down(0).next().innerHTML;
                if (contentLine.length > 30) {
                    contentLine = contentLine.slice(0,30) + '...';
                }
                contentLines.push(headerLine + ' ' + contentLine);
            }
        });
        return contentLines.join('<br/>');
    }
    giftOptionsTooltip.setTooltipContentLoaderFunction(getGiftOptionsTooltipContent);
    window.getGiftOptionsTooltipContent = getGiftOptionsTooltipContent;
//]]>

});
</script>
